package com.example.demo.controller;

import com.example.demo.exception.ThrowableException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

/**
 * @Author: cafe zhai
 * @Date: 2024/01/22/9:49
 * @Description:
 */
@Controller
@RequestMapping("/exception")
@Slf4j
public class ExceptionController {
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public ModelAndView method1(Model model) {
        HashMap<String, String> map = new HashMap<>();
        map.put("101", "F");
        map.put("202", "05");
        map.put("303", "00");

        //model.addAttribute("result", map);
        //模拟返回账号101，当number=101时，判断map的value，等于00则显示！
        //model.addAttribute("number", "101");

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("message.html");
        modelAndView.addObject("result", map);
        modelAndView.addObject("number", "101");
        return modelAndView;
    }

    private static String methodA() {
        int a = 1;
        int b = 3;
        try {
            b = a / 0;
        } catch (Exception e) {
            throw new ThrowableException("F1101", "MethodA Catch Error", e);
        }
        return String.valueOf(b);
    }

}
